/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package flightlifter;

import java.util.Vector;
import org.lwjgl.opengl.GL11;

/**
 *
 * @author Matt
 */
public class SmokeNode extends Node implements WiringConsumer {

    Point a;
    public Vector<PVector> history = new Vector();
    int cnt = 0;
    int running = 0;
    int rollercoaster = 0;

    public SmokeNode(Point a) {
        this.a = a;
    }

    public void physics() {
    }

    @Override
    public void render(int mode) {
        GL11.glPushMatrix();

        GL11.glTranslatef(a.pos.x, a.pos.y, a.pos.z);

        GL11.glScalef(.4f, .4f, .4f);
        GL11.glColor3f(0.5f, 0.5f, 0.3f);

        Draw.box();

        GL11.glPopMatrix();




        if (cnt == 10) {
            cnt = 0;
            history.add(a.pos.get());

        } else {
            cnt++;
        }

        GL11.glColor3f(1f, 1f, 1f);
        GL11.glBegin(GL11.GL_LINE_STRIP);
        for (PVector pnt : history) {
            // Drawing Using Triangles
            GL11.glVertex3f(pnt.x, pnt.y, pnt.z);
        }
        GL11.glVertex3f(a.pos.x, a.pos.y, a.pos.z);
        GL11.glEnd();


        if (rollercoaster == 1) {
            GL11.glColor3f(.25f, .25f, .25f);
            GL11.glBegin(GL11.GL_LINES);
            int i = 0;
            for (PVector pnt : history) {
                i++;
                if (i % 5 == 0) {
                    i = 0;
                    // Drawing Using Triangles
                    GL11.glVertex3f(pnt.x, pnt.y, pnt.z);
                    GL11.glVertex3f(pnt.x, 0, pnt.z);
                }
            }
            GL11.glVertex3f(a.pos.x, a.pos.y, a.pos.z);
            GL11.glEnd();
        }

    }

    @Override
    public PVector getCentroid() {
        return a.pos;
    }

    public PVector getScreenSpaceCentroid() {
        float[] ret = GLProject.project(a.pos.x, a.pos.y, a.pos.z);
        return new PVector(ret[0], ret[1], 0);
    }

    public SmokeNode(String[] line, Vector<Node> nodes) {
        this((Point) nodes.elementAt(Integer.parseInt(line[1])));
    }

    public String pickle(Vector<Node> nodes) {
        return "S,"
                + nodes.indexOf(a) + ",";


    }

    @Override
    public void setValue(float value) {
        if (value > .9f) {
            running = 1 - running;
        }
    }

    @Override
    public PVector getScreenCenter() {
        return getScreenSpaceCentroid();
    }

    public boolean dependsOn(Point p) {
        if (p == a) {
            return true;
        } else {
            return false;
        }
    }
}
